<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商品资料</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>

</head>
<body class="bg-eee">
    <header class="header">
        <div class="backPrevPage" onclick="historyBack()"></div>
        <div class="pageTitle">商家资料</div>
    </header>
    <section class="memberInfoPage HTML_BOX">
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <ul class="settings plr bg-fff">
            <li class="displayFlex">
                <span>LOGO</span>
                <div class="shopTx"><img class="userTx" src="../image/tx.png" /></div>
            </li>
            <li class="displayFlex">
                <span>商家名称</span>
                <div class="inputInfo"><input placeholder="请输入昵称" tyoe="text" /></div>
            </li>
            <li class="displayFlex">
                <span>English Name</span>
                <div class="inputInfo"><input placeholder="English Name" tyoe="text" /></div>
            </li>
            <li class="displayFlex">
                <span>手机号</span>
                <div class="inputInfo"><input placeholder="" readonly="" value="13637992261" tyoe="text" /></div>
            </li>
            <li class="displayFlex">
                <span>邮箱</span>
                <div class="inputInfo"><input readonly="" placeholder="邮箱地址" tyoe="text" /></div>
            </li>
        </ul>
        <div class="loginBtn f_c">保存</div>
    </section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var icon_id;
    apiready = function(){
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        ifCnAndEn();
        ready();
    };
    function ready(){
        getAjax(Interface.merchant_info,{token:token},function(res){
            console.log(JSON.stringify(res));
            var data = res.data.info;
            $(".userTx").attr("src",getImg(data.icon)).show();
            $(".settings input").eq(0).val(data.username);
            $(".settings input").eq(1).val(data.egusername);
            $(".settings input").eq(2).val(data.mobile||"");
            $(".settings input").eq(3).val(data.email||"");
        })
    }


    $(".loginBtn").click(function(){
        var layers = "";
        var isnull = false;
        $(".settings input").each(function(i,item){
            var val = $(item).val();
            if(val == "" && !isnull){
                switch(i){
                    case 0:
                    layers = "请输入昵称";
                    if(cnen==2){
                        layers='Please enter a nickname';
                    }
                    isnull = true;
                    break;  
                    case 1:
                    layers = "请输入英文昵称";
                    if(cnen==2){
                        layers='Please enter a English nickname';
                    }
                    isnull = true;
                    break;            
                }
            }
        });
        if(isnull){
            console.log(layers);
            pop.notice(layers);
            return;
        }
        var p = {
            token:token,
            username:$(".settings input").eq(0).val(),
            egusername:$(".settings input").eq(1).val(),
        }
        if(icon_id!=0){
            p.icon = icon_id;
        }
        console.log(JSON.stringify(p));
        pop.loading();
        getAjax(Interface.merchant_edit,p,function(res){
            pop.close();
            pop.notice(res.msg,1,function(){
                historyBack();
            })
        },function(res,err){})
    });
    $(".selctSex").click(function(){
        $(".sex").click();
    })
    //点击上传
    $(".tx").click(function(){
        var buttons = ['拍照', '从手机相册选择'];
        var cancel='取消';
        var title = '上传图片';
        if(cnen==2){
            buttons = ['Photograph', 'Selection from Mobile Phone Album'];
            title = 'Upload pictures';
            cancel = 'Cancel';
        }
        api.actionSheet({
             title:title,
             cancelTitle: cancel,
             buttons: buttons,
        }, function(ret, err) {
             if (ret) {
                 getPicture(ret.buttonIndex);
             }
        });
    })
    function getPicture(sourceType) {
            var texts =  {
                    stateText: '已选择*项',
                    cancelText: '取消',
                    finishText: '完成'
                };
        if(cnen==2){
            texts = {//（可选项）模块各部分的文字内容
                    stateText: '* items have been selected',
                    cancelText: 'Cancel',
                    finishText: 'Confirm'
                }
        }
        if (sourceType == 1) { // 拍照
            //获取一张图片
            api.getPicture({
                sourceType: 'camera',
                encodingType: 'png',
                mediaValue: 'pic',
                allowEdit: false,
                quality: 90,
                saveToPhotoAlbum: true
            }, function(ret, err) {
                if(ret.data==''){return;}
                if (ret) {
                    var imgSrc = ret.data;
                    if (imgSrc != "") {
                        //$api.attr(ele, 'src', imgSrc);
                    }
                    upload(ret.data,function(res){
                        icon_id =res.id;
                        $(".userTx").attr("src",getImg(res.pic)).load(function(){
                          pop.close();   
                        });;
                    });
                }
            });
        } else if (sourceType == 2) { // 从相机中选择
            //UIMediaScanner 是一个多媒体扫描器，可扫描系统的图片、视频等多媒体资源
            var obj = api.require('UIMediaScanner');
            obj.open({
                type: 'all',//返回的资源种类,picture（图片）,video（视频）,all（图片和视频）
                column: 4,//（可选项）图片显示的列数，须大于1
                max: 1,
                sort: { //（可选项）图片排序方式,asc（旧->新）,desc（新->旧）
                    key: 'time',
                    order: 'desc'
                },
                texts: texts,
                styles: {
                    bg: '#fff',
                    mark: {
                        icon: '',
                        position: 'bottom_right',
                        size: 20
                    },
                    nav: {
                        bg: '#eee',
                        stateColor: '#000',
                        stateSize: 18,
                        cancleBg: 'rgba(0,0,0,0)',
                        cancelColor: '#000',
                        cancelSize: 18,
                        finishBg: 'rgba(0,0,0,0)',
                        finishColor: '#000',
                        finishSize: 18
                    }
                }
            }, function(ret) {
                console.log(JSON.stringify(ret));
                if(ret.eventType=='cancel'){return;}
                if (ret) {
                    if (ret.hasOwnProperty("list")) {
                        api.showProgress({
                            title: '正在上传...',
                            modal: true
                        });
                    }
                    console.log(ret.list[0].path);
                    upload(ret.list[0].path,function(res){
                        
                        icon_id =res.id;
                        $(".userTx").attr("src",getImg(res.pic)).load(function(){
                          pop.close();   
                        });;
                    });
                }
            });
        
        }
    }
</script>
<script type="text/javascript">
    function ifCnAndEn(){
        if(cnen==2){
            $(".pageTitle").html('My Account');
            $(".settings span").eq(1).html("Merchant Name");
            $(".settings span").eq(3).html("Phone");
            $(".settings span").eq(4).html("Email");
            $(".loginBtn").html('Save');
        }
    }
</script>
</html>